﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Crosland.Automotriz.Seguridad.Business;
using Crosland.Automotriz.Seguridad.Entity;
using DevExpress.Web.ASPxTreeList;

namespace Crosland.Automotriz.Web
{
    public partial class MasterReporte : System.Web.UI.MasterPage
    {
        clsReporteLogic logicReporte = new clsReporteLogic();
        protected void Page_Load(object sender, EventArgs e)
        {
            //if(!IsPostBack)
            //{

            


            
                this.listarTreeListReport();
                treListReporte.DataBind();
                //TreeListNode firstUnread = treListReporte.FindNodeByFieldValue("IsNew",true);
                //firstUnread.Focus();
                treListReporte.ExpandToLevel(3);
                //treListReporte.PageIndex = -1;
            //}
                if (Session["nodo"] != null)
                {
                    TreeListNode node = (TreeListNode)Session["nodo"];
                    treListReporte.FindNodeByKeyValue(node.Key).Selected = true;
                }

        }

        clsReporteLogic reporLogic = new clsReporteLogic();



        void listarTreeListReport()
        {

            treListReporte.DataSource = logicReporte.listarReport();
            treListReporte.ParentFieldName = "ID_PADRE";
            treListReporte.DataBind();

        }

      

        protected void treListReporte_PageIndexChanged(object sender, EventArgs e)
        {
            this.listarTreeListReport();
        }

        protected void treListReporte_FocusedNodeChanged(object sender, EventArgs e)
        {
            TreeListNode node = treListReporte.FocusedNode;
            Session["nodo"] = node;

            if (node.Expanded == false)
            {
                string query = treListReporte.FocusedNode["DES_URL"].ToString();
                Response.Redirect(query);

            }

        }

        protected void btnCollapse_Click(object sender, ImageClickEventArgs e)
        {
            this.asp.Visible = !this.asp.Visible;
        }

        //protected void treListReporte_CustomDataCallback(object sender, TreeListCustomDataCallbackEventArgs e)
        //{
        //    string key = e.Argument.ToString();
        //    TreeListNode node = treListReporte.FindNodeByKeyValue(key);
        //}


       
       

    
        }
    
}